#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>

int g_value = 100;
int main()
{
    pid_t id = fork();
    if(id == 0)
    {
        //child
        int cnt = 5;
        while(1)
        {
            printf("I am a child, pid:%d, ppid:%d, g_value:%d, &g_value:%p\n", getpid(), getppid(), g_value, &g_value);
            sleep(2);
            if(cnt)
            {
                cnt--;
            }
            else
            {
                g_value = 200;
                printf("child change g_value : 100->200\n");
                cnt--;

            }
        }
    }
    else if(id > 0)
    {
        //parent
        printf("I am a parent, pid:%d, ppid:%d, g_value:%d, &g_value:%p\n", getpid(), getppid(), g_value, &g_value);
        sleep(2);
    }
    else
    {
        ;
    }

    return 0;
}
